package com.silvaborgesmauricio.mydbversioning.core;

import java.util.ArrayList;
import java.util.List;

public class ChangeSet implements Comparable<ChangeSet> {

	private Integer id;
	private RepositoryInfo repositoryInfo;
	private List<Unit> units;

	public ChangeSet(){
		super();
	}
	public ChangeSet(Integer id){
		this();
		this.id = id;
	}
	
	
	public void commit() {
		for (Unit unit : units) {
			try {
				unit.commit();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				// add to conflict list if the exception was a conflict
				e.printStackTrace();
			}
		}
	}

	public void update() {

	}

	public int compareTo(ChangeSet o) {
		// TODO Auto-generated method stub
		return 0;
	}

	public static boolean existsConflictChangeSet(Unit unit) {
		// TODO: if there is another ChangeSet with the same unit in a newest
		// version, return true. Else case, return false
		return true;
	}

	public boolean existsConflictChangeSet() {
		// TODO: if there is another ChangeSet with the same unit in a newest
		// version, return true. Else case, return false
		for (Unit unit : units) {
			if (ChangeSet.existsConflictChangeSet(unit))
				return true;
		}
		return false;
	}
}
